
Page({
  data: {
    // 用户信息
    userInfo: {},
    
    // 会员数据
    memberData: {
      level: '银卡会员',         // 会员等级
      levelCode: 'gold',        // 会员等级代码
      levelProgress: 21.3,      // 升级进度百分比
      nextLevel: '金卡会员',    // 下一等级
      nextLevelScore: 3000,     // 下一等级所需分数
      currentScore: 640,        // 当前分数
      validUntil: '2026-06-12', // 会员有效期
      points: 1258,             // 会员积分
      consumption: 5680,        // 累计消费金额
      daysSinceMember: 512,     // 会员时长(天)
      benefits: [              // 会员权益
        { id: 1, name: '生日特权',description: '生日当月享受双倍积分' },
        { id: 2, name: '优先发货', description: '订单优先处理，快速发货' },
        { id: 3, name: '专属客服',  description: '享受7×24小时专属客服服务' }
      ],
      activities: [            // 会员活动
        { 
          id: 1, 
          title: '会员日大促销', 
          date: '2023-06-20', 
          description: '会员日全场商品8折起，还有额外积分奖励',
          image: '/image/01.jpg' 
        },
        { 
          id: 2, 
          title: '夏季新品发布会', 
          date: '2023-07-05', 
          description: '抢先体验夏季新品，参与互动赢取奖品',
          image: '/image/01.jpg' 
        },
        { 
          id: 3, 
          title: '会员专属折扣周', 
          date: '2023-07-15', 
          description: '连续7天享受会员专属折扣，部分商品低至5折',
          image: '/image/01.jpg' 
        }
      ],
      levels: [                // 会员等级定义
        { id: 1, name: '普通会员', score: 0},
        { id: 2, name: '银卡会员', score: 1000 },
        { id: 3, name: '金卡会员', score: 3000 },
        { id: 4, name: '白金会员', score: 6000 },
        { id: 5, name: '钻石会员', score: 10000}
      ]
    },
    
    // 弹窗状态
    showShareModal: false,
    showActivityModal: false,
    currentActivity: {}
  },

  onLoad() {
    // 从本地存储获取用户信息
    const userInfo = wx.getStorageSync('userInfo') || {};
    this.setData({
      userInfo
    });
  },

  // 返回上一页
  goBack() {
    wx.navigateBack();
  },


  // 显示活动详情弹窗
  showActivityDetail(e) {
    const activityId = e.currentTarget.dataset.id;
    const activity = this.data.memberData.activities.find(item => item.id === activityId);
    
    if (activity) {
      this.setData({
        showActivityModal: true,
        currentActivity: activity
      });
    }
  },

  // 关闭活动详情弹窗
  closeActivityModal() {
    this.setData({
      showActivityModal: false,
      currentActivity: {}
    });
  },

  // 报名活动
  registerActivity() {
    wx.showToast({
      title: '报名成功',
      icon: 'success'
    });
    this.closeActivityModal();
  }
});